/**
 * Created by user on 2018/11/12.
 */
import CryptoJS from 'crypto-js'
const BaseKey = '0880076B18D7EE81'
const BaseIv = 'CB3EC842D7C69578'

const encryption = d => {
  var key  = CryptoJS.enc.Utf8.parse(BaseKey);
  var iv   = CryptoJS.enc.Utf8.parse(BaseIv);
  var encrypted =CryptoJS.AES.encrypt(JSON.stringify(d), key,
      {
          iv:iv,
          mode:CryptoJS.mode.CBC,
          padding:CryptoJS.pad.Pkcs7
      });
  return encrypted.toString()
}

const decryption = d => {
  var key  = CryptoJS.enc.Utf8.parse(BaseKey);
  var iv   = CryptoJS.enc.Utf8.parse(BaseIv);
  var decrypted =CryptoJS.AES.decrypt(d, key,
      {
          iv:iv,
          mode:CryptoJS.mode.CBC,
          padding:CryptoJS.pad.Pkcs7
      });
  return JSON.parse(decrypted.toString(CryptoJS.enc.Utf8))
}


export { encryption, decryption }
